var kettleServerLogParam=null;
$(document).ready(function () {
	
		//选择节点
		$('#comboxNode').combobox({
			url: BASE_URL_KETTLE_SLAVE_SERVER_CRUD + '?v=' + Math.random(),
			valueField: 'id',
		    textField: 'name',
		    method:'get',
			editable: false,
		    loadFilter: function(data){
		    	return data._embedded.kettleSlaveServers;
		    },
			onLoadSuccess:function(){
				var data = $('#comboxNode').combobox('getData');
 				$("#comboxNode ").combobox('select',data[0].id);
				$("#datagrid").datagrid({
					url : BASE_URL_SLAVE_SERVER_LOG_SEARCH + '/findByExample' + '?v=' + Math.random(),
					method:'get',
					autoRowHeight:true,
					nowrap:false,
					singleSelect:true,
					rownumbers:true,
					striped:true,
					scrollbarSize:0,
					selectOnCheck:false,
					onClickRow: function (rowIndex, rowData) {
								$(this).datagrid('unselectRow', rowIndex);
							},
					columns:[[
								{field:'createTime',title:'记录时间',width:20},
								{field:'contents',title:'日志内容',width:80}
							]],
					onLoadSuccess:function(data){
						if(data.rows.length > 0)
						{
							$(".data_con").css("visibility","visible");
							setTimeout(function(){
								$("#datagrid").parent().addClass("text_left");
								var kettle = data.rows[0];
								$("#kettName").text(kettle.kettleSlaveServiceName);
								$("#kettHostName").text(kettle.kettleSlaveServiceHostName);
								/*$("#keetPort").text(kettle.kettleSlaveServicePort);*/
								$("#kettIsMaster").text(kettle.kettleSlaveServiceIsMaster?"主服务器":"从服务器");
							},500);
						}else{
							$(".loading_con td").text("");
							$(".data_con").css("visibility","hidden");
							$.messager.alert("提示","<p>你查询的日志记录时间没有内容！</p>", "info");
						}
					},
					loadFilter:function(data){
						return {
									total: data.totalElements,
									rows: data.content
								}
					},
					//条件查询
					onBeforeLoad:function(param){
						$(".datagrid-header-rownumber").text("序号");
						param.page -= 1;
						param.size = param.rows;
						delete param.rows;
						
						var id = $('#comboxNode').combobox('getValue');
						param.id = id;
						
						var beginOfCreateTime = $('#txtBeginTime').datetimebox('getValue')
						if(beginOfCreateTime!=""){
							param.beginOfCreateTime = beginOfCreateTime;
						}
						
						var endOfCreateTime = $('#txtEndTime').datetimebox('getValue');
						if(endOfCreateTime!=""){
							param.endOfCreateTime = endOfCreateTime;
						}
						
						kettleServerLogParam = param;
						
					}
				});
			}
		});
		

/*		var jsonstr = {"total":1,"rows":[{"time":"2015-09-12 00:00:30.560","name":"Kettle服务节点监控程序启动成功"},
					   {"time":"2015-09-12 00:00:00.670","name":"Kettle服务节点看门狗程序启动成功"},
					   {"time":"2015-09-12 15:21:00.680","name":"服务器内存占用率93%"}]};  
		$("#datagrid").datagrid('loadData', jsonstr);*/
});
//查询
function onSearch(){
	dataRetrieval('#txtBeginTime', '#txtEndTime');
}

//导出
function exportData(){
	$('#datagrid').datagrid({
		url:BASE_URL_SLAVE_SERVER_LOG_SEARCH + '/findByExample' + '?v=' + Math.random()
	});
	var param = JSON.stringify(kettleServerLogParam);
	location.href= BASE_URL_EXPORTDATA_FILE + '/KettleServerLogExport?param='+param;
}